Skip to content

fix(score): read real Claude Code transcripts - #7

Merged
gold-silver-copper merged 1 commit into
mainfrom
fix/score-read-real-transcripts
Oct 26, 2026
Merged

gold-silver-copper merged 1 commit into
mainfrom
fix/score-read-real-transcripts

Conversation

@gold-silver-copper

@gold-silver-copper gold-silver-copper commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

What and why

agent score read nothing from real Claude Code transcripts. The serde structs required fields literally named _uuid, _role, _id, _text, _tool_use_id, … which real transcripts never have (they use uuid, role, id, …). Every assistant line failed to parse, was silently skipped, and every session was graded as if it ran zero commands (found during #6, KB tasks/harmony-2768).

This PR:

  • Parses only what the scorer uses. An assistant line needs sessionId, timestamp and message.content; a content block is either tool_use (name, input) or ignored. Every other line type (user, attachment, mode, ai-title, …), block type (text, thinking, …) and unknown field is ignored, so new transcript fields don't break it.
  • Counts unreadable lines (skipped_lines, in --json and in the Markdown summary when non-zero) instead of dropping them silently. --json also gains assistant_messages (assistant lines read).
  • Doesn't grade an unreadable file as perfect. A session with no readable assistant message is reported on stderr and not scored; if no session is readable the command fails with No readable sessions to score.
  • Fixes the project dir name. Claude Code turns every non-alphanumeric character into -, not only /: /home/gsc/.cache/p → -home-gsc--cache-p, …/harmony/.worktrees/x → …-harmony--worktrees-x (checked against the dirs in ~/.claude/projects/). On main, agent score in any path with a ., _ or space looked in the wrong dir.

Not handled (all pre-existing, and none seen in the local ~/.claude/projects/): a path with a non-BMP character such as an emoji (JavaScript likely makes that --, this makes -); Windows, where canonicalize() adds a \\?\ prefix; and Claude Code shortening very long dir names (over ~200 chars) with a hash suffix. There's nothing local to check the exact rules against, so they're left out.

Verification

Same real session (~7,000 lines, 994+ Bash calls), copied into a scratch HOME. Before (main):

# Session Score:  (C)
| Meta-command ratio | 100% | A ✓ | 33% |
| Workspace discovery | 0% | F ✗ | 27% |
| Cross-repo awareness | 100% | A ✓ | 27% |
| Guard effectiveness | 100% | A ✓ | 13% |
- Tool calls: 0
- Git commands: 0 (0 meta, 0 bare)
- Commits: 0

After:

# Session Score: <session-id> (F ✗)
| Meta-command ratio | 0% | F ✗ | 33% |
| Workspace discovery | 0% | F ✗ | 27% |
| Cross-repo awareness | 0% | F ✗ | 27% |
| Guard effectiveness | 100% | A ✓ | 13% |
- Tool calls: 999
- Git commands: 562 (1 meta, 561 bare)
- Commits: 51

Hand count with jq over the same file: 999 Bash tool_use blocks, 562 containing git, 1 starting with meta git, 51 containing git commit, 0 meta git status/diff (hence 0% awareness), no meta context/meta project list. All match. (The low grade is accurate: that session used plain git in sub-repos.)

From a scratch HOME at a path containing .cache, main fails with Expected directory: …/-home-gsc-.cache-claude-tmp-… while Claude Code's dir is …/-home-gsc--cache-claude-tmp-…; the fix finds it. A file holding only a mode line and a non-JSON line prints Not scoring …: no assistant messages could be read (1 unreadable lines) and exits 1.

Tests: new test_parse_real_transcript_format reads tests/fixtures/transcript.jsonl, built from the real line shapes (real keys, placeholder values; no prompts, paths, emails or tokens) with user/attachment/mode/last-prompt lines, thinking/text/tool_use blocks, a non-Bash tool, and one truncated line. Run against main's parser (with the skipped_lines assertion removed, since that field doesn't exist on main) it fails with left: "" right: "fixture-session"; it passes here. cargo test and cargo clippy --all-targets --all-features -- -D warnings pass locally.

Look closely at

  • handle_score now skips unreadable sessions and errors only when none are readable, so --recent N still scores the readable ones.
  • Message.content is now Vec<ContentBlock>: an assistant line whose content isn't an array counts as unreadable. Real assistant lines always use an array (2,077/2,077 in the sampled session).

Implements KB tasks/harmony-2770.

The transcript structs required fields named `_uuid`, `_role`, `_id`,
`_text` and so on, which real transcripts never contain, so every
assistant line failed to parse and every session scored as if it ran no
commands. Declare only the fields the scorer uses and let serde ignore
the rest. Count unreadable lines, and report sessions with no readable
assistant message instead of grading them.

Name project dirs like Claude Code does: every non-alphanumeric
character becomes `-`, not only `/` (`.worktrees` -> `--worktrees`).

Implements [[tasks/harmony-2770]]
@coderabbitai

coderabbitai Bot commented Oct 26, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 371e81fa-7a79-44a4-adb1-cc5d7fb87c5d
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@gold-silver-copper
gold-silver-copper merged commit a8b91d2 into main Oct 26, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant